package de.koller.million.card.engine.util;

import de.koller.oceanFramework.OceanException;
import java.util.Random;

public class Utils {
	
	public static int prop( Random r, int... weights ) {
		int sum = 0;
		for( int i = 0; i < weights.length; i++ )
			sum += weights[i];
		
		int result = r.nextInt( sum );
		int j = 0;
		for( int i = 0; i < weights.length; i++ ) {
			j += weights[i];
			if( result < j )
				return i;
		}
		
		throw new OceanException( "should not reach" );
	}
	
}
